package cn.wolfcode.service.impl;

import cn.wolfcode.domain.ConsumptionItem;
import cn.wolfcode.mapper.ConsumptionItemMapper;
import cn.wolfcode.service.IConsumptionItemService;
import cn.wolfcode.util.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
public class ConsumptionItemServiceImpl implements IConsumptionItemService {

    @Autowired
    private ConsumptionItemMapper consumptionItemMapper;

    @Override
    @Transactional
    public void save(ConsumptionItem consumptionItem) {
        //创建用户
        consumptionItem.setCreateUserId(UserContext.getEmployee().getId());
        //创建时间
        consumptionItem.setCreateTime(new Date());

        consumptionItemMapper.insert(consumptionItem);
    }

    @Override
    @Transactional
    public void delete(Long id) {
        consumptionItemMapper.deleteByPrimaryKey(id);
    }

    @Override
    @Transactional
    public void update(ConsumptionItem consumptionItem) {
        consumptionItemMapper.updateByPrimaryKey(consumptionItem);
    }

    @Override
    public ConsumptionItem get(Long id) {
        return consumptionItemMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<ConsumptionItem> listAll() {
        return consumptionItemMapper.selectAll();
    }

    @Override
    public List<ConsumptionItem> queryByCno(String cno) {
        return consumptionItemMapper.selectByCno(cno);
    }
}
